﻿#ifndef PST_POSESETTINGDATA_H
#define PST_POSESETTINGDATA_H

#include <QObject>
#include <QDomElement>
#include <QDomDocument>
#include <QDomAttr>
#include "BaseModule/GlobalHelper.h"

namespace pst
{
    class PoseSettingData : public QObject
    {
        Q_OBJECT

    public:
        PoseSettingData(QObject* parent = nullptr) :QObject(parent) {}

        void setTranslationX(double x) { m_translationX = x; }
        double getTranslationX() const { return m_translationX; }
        void setTranslationY(double y) { m_translationY = y; }
        double getTranslationY() const { return m_translationY; }
        void setTranslationZ(double z) { m_translationZ = z; }
        double getTranslationZ() const { return m_translationZ; }

        void setRotationTheta(double theta) { m_rotationTheta = theta; }
        double getRotationTheta() const { return m_rotationTheta; }
        void setRotationPhi(double phi) { m_rotationPhi = phi; }
        double getRotationPhi() const { return m_rotationPhi; }

        void setScaleFactor(double factor) { m_scaleFactor = factor; }
        double getScaleFactor() const { return m_scaleFactor; }

                /// @brief 文件写出至工程文件
        QDomElement& writeToProjectFile(QDomDocument* doc, QDomElement* element, bool isdiso = false)
        {
            QDomElement _PoseSettingDataDataRoot = doc->createElement("PoseSettingData");

            GlobalHelperInstance->createDomElement(doc, &_PoseSettingDataDataRoot, "TranslationX", QString::number(m_translationX));
            GlobalHelperInstance->createDomElement(doc, &_PoseSettingDataDataRoot, "TranslationY", QString::number(m_translationY));
            GlobalHelperInstance->createDomElement(doc, &_PoseSettingDataDataRoot, "TranslationZ", QString::number(m_translationZ));

            GlobalHelperInstance->createDomElement(doc, &_PoseSettingDataDataRoot, "RotationTheta", QString::number(m_rotationTheta));  
            GlobalHelperInstance->createDomElement(doc, &_PoseSettingDataDataRoot, "RotationPhi", QString::number(m_rotationPhi));

            GlobalHelperInstance->createDomElement(doc, &_PoseSettingDataDataRoot, "ScaleFactor", QString::number(m_scaleFactor));

            element->appendChild(_PoseSettingDataDataRoot);

            return _PoseSettingDataDataRoot;
        }
        /// @brief 从工程文件读入数据
        void readFromProjectFile(QDomElement* element, bool isdiso = false)
        {
            auto _TranslationXNodeList = element->elementsByTagName("TranslationX");
            m_translationX = _TranslationXNodeList.item(0).toElement().text().toDouble();
            auto _TranslationYNodeList = element->elementsByTagName("TranslationY");
            m_translationY = _TranslationYNodeList.item(0).toElement().text().toDouble();
            auto _TranslationZNodeList = element->elementsByTagName("TranslationZ");
            m_translationZ = _TranslationZNodeList.item(0).toElement().text().toDouble();

            auto _RotationThetaNodeList = element->elementsByTagName("RotationTheta");
            m_rotationTheta = _RotationThetaNodeList.item(0).toElement().text().toDouble();
            auto _RotationPhiNodeList = element->elementsByTagName("RotationPhi");
            m_rotationPhi = _RotationPhiNodeList.item(0).toElement().text().toDouble();

            auto _ScaleFactorNodeList = element->elementsByTagName("ScaleFactor");
            m_scaleFactor = _ScaleFactorNodeList.item(0).toElement().text().toDouble();
        }

    private:
        double m_translationX{ 0. };
        double m_translationY{ 0. };
        double m_translationZ{ 0. };

        double m_rotationTheta{ 0. };
        double m_rotationPhi{ 0. };

        double m_scaleFactor{ 1. };
    };
}
#endif
